# -*- coding: utf-8 -*-
'''
Created on 15-12-2012

@author: LONG HOANG GIANG
'''

from Model.storymodelv2 import StoryModel
from CrawlerLib2.AESCipher import AESCipher
import os


def encrypt():
    
    db = StoryModel(DATABASE)
    db.open()
    destDb = StoryModel("{0}enc".format(DATABASE))
    destDb.open(True)
    stories = db.get_all_stories()
    cipher = AESCipher()
    for story in stories:
        title = story[2]
        print cipher.encrypt(title)
        destDb.add_story(title, story[3], story[1])
    db.close()
    destDb.close()
    


if __name__ == '__main__':
    
    DATABASE = "/longhoanggiang/database/{0}".format("truyennguoilon")
    
    print '> start encrypt database'
    encrypt()
    print '> finished'
    os._exit(1)